//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.model;

import javax.servlet.http.HttpServletRequest;

public class RequestInfo {
    protected String reqUrl;
    protected String ipAddr;
    protected String userAgent;
    protected String osType;
    protected boolean weixin;

    public RequestInfo(HttpServletRequest request) {
        this.reqUrl = request.getRequestURI();
        this.ipAddr = this.getIpAddr(request);
        this.userAgent = request.getHeader("user-agent");
        String os = "unknown";
        if(this.userAgent != null && this.userAgent.length() > 0) {
            String agent = this.userAgent.toLowerCase();
            if(agent.contains("windows phone")) {
                os = "WPhone";
            } else if(agent.contains("windows")) {
                os = "Windows";
            } else if(agent.contains("android")) {
                os = "Android";
            } else if(agent.contains("iphone")) {
                os = "iPhone";
            } else if(agent.contains("ipad")) {
                os = "iPad";
            } else if(agent.contains("ucweb")) {
                if(agent.contains("ios")) {
                    os = "iPhone";
                } else if(agent.contains("linux")) {
                    os = "Android";
                } else {
                    os = "Mobile";
                }
            } else if(agent.contains("macintosh")) {
                os = "Mac";
            } else if(agent.contains("x11") && agent.contains("linux")) {
                os = "Linux";
            } else if(agent.contains("j2me") || agent.contains("nokia") || agent.contains("blackberry") || agent.contains("mobile")) {
                os = "Mobile";
            }

            if(agent.contains("micromessenger")) {
                this.weixin = true;
            }
        }

        this.osType = os;
    }

    public String getReqUrl() {
        return this.reqUrl;
    }

    public void setReqUrl(String reqUrl) {
        this.reqUrl = reqUrl;
    }

    public String getIpAddr() {
        return this.ipAddr;
    }

    public void setIpAddr(String ipAddr) {
        this.ipAddr = ipAddr;
    }

    public String getUserAgent() {
        return this.userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getOsType() {
        return this.osType;
    }

    public void setOsType(String osType) {
        this.osType = osType;
    }

    public boolean isWeixin() {
        return this.weixin;
    }

    public void setWeixin(boolean weixin) {
        this.weixin = weixin;
    }

    public boolean chkAllowIp(String ip) {
        if(ip != null && ip.length() != 0 && !"*.*.*.*".equals(ip)) {
            if(this.ipAddr != null && this.ipAddr.length() != 0) {
                try {
                    String[] e = this.ipAddr.split(",")[0].trim().split(".");
                    if(e.length != 4) {
                        return false;
                    }

                    String[] ipss = ip.trim().split(",");
                    String[] arr$ = ipss;
                    int len$ = ipss.length;

                    for(int i$ = 0; i$ < len$; ++i$) {
                        String ip1 = arr$[i$];
                        ip1 = ip1.trim();
                        if(ip1.length() != 0) {
                            boolean b = true;
                            if(ip1.startsWith("-")) {
                                b = false;
                                ip1 = ip1.substring(1);
                            }

                            String[] s1 = ip1.split(",");
                            if(s1.length == 4) {
                                int n;
                                for(n = 0; n < 4 && ("*".equals(s1[n]) || s1[n].equals(e[n])); ++n) {
                                    ;
                                }

                                if(n == 4) {
                                    return b;
                                }
                            }
                        }
                    }
                } catch (Exception var11) {
                    ;
                }

                return false;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }

    private String getIpAddr(HttpServletRequest request) {
        StringBuffer ipAddr = new StringBuffer();
        String ip = request.getHeader("x-forwarded-for");
        if(ip != null && ip.length() > 0 && !"unknown".equalsIgnoreCase(ip)) {
            ipAddr.append(ip);
        }

        ip = request.getHeader("Proxy-Client-IP");
        if(ip != null && ip.length() > 0 && !"unknown".equalsIgnoreCase(ip) && ipAddr.indexOf(ip) < 0) {
            if(ipAddr.length() > 0) {
                ipAddr.append(",");
            }

            ipAddr.append(ip);
        }

        ip = request.getHeader("WL-Proxy-Client-IP");
        if(ip != null && ip.length() > 0 && !"unknown".equalsIgnoreCase(ip) && ipAddr.indexOf(ip) < 0) {
            if(ipAddr.length() > 0) {
                ipAddr.append(",");
            }

            ipAddr.append(ip);
        }

        ip = request.getRemoteAddr();
        if(ip != null && ip.length() > 0 && !"unknown".equalsIgnoreCase(ip) && ipAddr.indexOf(ip) < 0) {
            if(ipAddr.length() > 0) {
                ipAddr.append(",");
            }

            ipAddr.append(ip);
        }

        return ipAddr.toString();
    }
}
